package cn.zzszxyy.hr.service;

import cn.zzszxyy.hr.model.MenuEntity;
import cn.zzszxyy.hr.repository.MenuRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 作者:张伟
 * <p>
 * 联系:adamzzww@163.com
 * 时间:2016-11-27
 * 说明:无
 */
@Service
public class MenuService {

    @Autowired
    private MenuRepository menuRepository;

    public Page<MenuEntity> findByMenuNameLike(String menuName, int pageIndex, int pageSize) {
        PageRequest pageRequest = new PageRequest(--pageIndex, pageSize);
        return menuRepository.findByMenuNameLike(menuName, pageRequest);
    }

    public List<MenuEntity> findAll() {
        return menuRepository.findAll();
    }

    public List<MenuEntity> findMenusByRoleId(int roleId) {
        return menuRepository.findMenusByRoleId(roleId);
    }

    public List<MenuEntity> findMenusByUserId(int userId) {
        return menuRepository.findMenusByUserId(userId);
    }

    public Page<MenuEntity> findAllWithPage(int pageIndex, int pageSize) {
        PageRequest pageRequest = new PageRequest(--pageIndex, pageSize);
        Page<MenuEntity> menuList = menuRepository.findAll(pageRequest);
        return menuList;
    }

    public MenuEntity findOne(int id) {
        return menuRepository.findOne(id);
    }

    public MenuEntity save(MenuEntity menuEntity) {
        return menuRepository.save(menuEntity);
    }

    public void delete(int id) {
        //删除：本表记录
        menuRepository.delete(id);
    }

}
